// 工厂函数fuunction, 是最重要的部分之一
function addNumbers(a: number, b: number): number {
  const result = a + b;
  return result;

  // console.log(undefined);
}

console.log(addNumbers(3, 7));

function subtractNUmbers(a: number, b: number): number | undefined {
  if (typeof a !== "number" || typeof b !== "number") return;
  if (a < b || a <= 0 || b <= 0) return;
  return a - b;
}

console.log(subtractNUmbers(21, 12));
console.log(subtractNUmbers(5, 3));

// challenge Function

// ?1calculateAverage
function calculateAverage(num1: number, num2: number): number {
  return (num1 + num2) / 2;
}
console.log(calculateAverage(4, 3));

// ?addString
function addString(a: string, b: string): string {
  return a.concat(b);
}
console.log(addString("hello", "world"));

// ?Square
function Square(number: number): number {
  return number * number;
}
console.log(Square(2));

// ?sumOfSquares
function sumOfSquares(n1: number, n2: number): number {
  return n1 ** 2 + n2 ** 2;
}
console.log(sumOfSquares(3, 4));
